import { trim, isEmpty } from 'lodash';
import { Op } from 'sequelize';
import BaseController from './base';
import OpenUserModel from '../models/open-user';

// order docs https://sequelize.org/docs/v6/core-concepts/model-querying-basics/
class OpenUserController extends BaseController {
  getModel() {
    return OpenUserModel;
  }

  /**
   * 解析查询条件
   * @returns {Object}
   */
  getFindWhere(req) {
    const {
      nickname, openid,
    } = req.query;
    const { hotel_id } = req.user;

    const where = { hotel_id };
    if (openid) {
      where.openid = openid;
    }

    if (trim(nickname)) {
      where.nickname = trim(nickname);
    }

    return { where };
  }
}

export default new OpenUserController();
